package com.example.resource_014;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public void click(View view) throws XmlPullParserException, IOException {
		Button buttion = (Button) findViewById(R.id.button1);
		int test_color = this.getResources().getColor(R.color.test_color);
		buttion.setTextColor(test_color);
		String welcome = this.getString(R.string.welcome);
		buttion.setText(welcome);

		// ------xml
		String text = "";
		XmlResourceParser xrp = this.getResources().getXml(R.xml.users);
		while (xrp.getEventType() != xrp.END_DOCUMENT) {
			if (xrp.getEventType() == xrp.START_TAG) {
				String tagName = xrp.getName();
				if (tagName.equals("user")) {
					String name = xrp.getAttributeValue(0);
					String telephone = xrp.getAttributeValue(1);
					text += ("name:" + name + ";telephone:" + telephone + "\n");
				}
			}

			xrp.next();
		}
		TextView textView = (TextView) findViewById(R.id.textView1);
		textView.setText(text);
	}
	
	public void click1(View view){
		Drawable drawable = this.getResources().getDrawable(R.drawable.a1);
		this.getWindow().setBackgroundDrawable(drawable);
	}
	
	public void click2(View view){
		Drawable drawable = this.getResources().getDrawable(R.drawable.a2);
		this.getWindow().setBackgroundDrawable(drawable);
	}
}
